<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./site/public/groups/_pre.php, $Author:  $ */

$oSecurityService = &App::getModuleService('Account', 'Security');
/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */

$oSecurityService->checkAccess('groups'); 

//get curren user
$oCurrUser = $oSecurityService->getCurrentUser();

//----------------------------------
//get group owner
$oReq = &App::getRequest();
$sId = $oReq->get('id');
$sGroupAct = $oReq->get('act');

if(!empty($sId)) 
{
	$aUrl=App::getUrl();
	$aPages=array('view','members','gallery','forum');
	if(isset($aUrl->aParams['2']) && in_array($aUrl->aParams['2'], $aPages) && !isset($aUrl->aParams['3'])) 
	{
		$sGroupId=$sId;
	}
}

if(isset($sGroupId) && !empty($sGroupId)) {
$oGroupsSrv = &App::getModuleService('Groups', 'Groups');
$aGroupInfo=$oGroupsSrv->getGroupData($sGroupId);
//d(App::getUrl());
if($aGroupInfo) {
//get profile owner user
$oSrvAcc = &App::getModuleService('Account', 'Account');
$oUser = &$oSrvAcc->getByUsername($aGroupInfo['user']);
if (!$oUser)
{
    App::gotoUrl('public');
}
//--
$bIsOwner = ($oCurrUser && ($oCurrUser->aData['id'] == $oUser->aData['id']));

//perform  check on blocked/not-blocked
$bIsBlocked = false;
if (!$oSecurityService->isStaff() && !$bIsOwner && ('public.user.blocked' != App::getPageName()))
{
    $oSrvBlock = &App::getModuleService('Account', 'Block');
    /* @var $oSrvBlock PhpFox_Mod_Account_ServiceBlock */
    $bIsBlocked = $oSrvBlock->isBlocked($oUser, $oCurrUser);

    if ( $bIsBlocked )
    {
        App::gotoUrl('public.groups.blocked', array('name'=>$aGroupInfo['user']));
    }
}
}
}
//var_dump($aGroupInfo); exit;

//-----------------------------------

//create tabs menu
$aMenuItems = array(
	'public.groups'           => App::format('menu.groups.main'),
    'public.groups.mygroups'  => App::format('menu.groups.submit.mygroups'),
    'public.groups.edit'      => App::format('menu.groups.myitems.create'),
);

$aParams = array(
	'sTemplate' => 'TabbedMenu',
    'aMenuItems' => $aMenuItems,
);

$oGroupMenu = App::getModuleComponent('Menu', 'Menu', $aParams);
$srcTabbedMenu = $oGroupMenu->process();
$oTpl = &App::getTemplate();
$oTpl->assignSrc(array(
	'srcTabbedMenu' => $srcTabbedMenu,
    'oCurrUser'     => $oCurrUser,
    'bShoutbox'     => App::getSetting('show_shoutbox'),
    'bLogin'        => !($oCurrUser) ? 0 : 1,
));
?>